package com.unicom.wostore.dsp.controller;

import com.alibaba.fastjson.JSON;
import com.unicom.wostore.dsp.service.TestService;
import com.unicom.wostore.dsp.utils.RedisApi;
import com.unicom.wostore.dsp.vo.DspDetailVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by huangjie on 2017/2/20.
 */
@Controller
@RequestMapping("test")
public class TestAction {

    @Autowired
    private TestService testService;

    @Autowired
    RedisApi redisApi;

    private final static String REDISKEY = "dspTestData:data";

    @ResponseBody
    @RequestMapping("hi")
    public List<DspDetailVO> sayHi(){

        redisApi.setObj(REDISKEY,JSON.toJSONString(testService.getDspDetailList()));
        System.out.print(redisApi.getObj(REDISKEY));

        List<DspDetailVO> dataList= (List<DspDetailVO>)redisApi.getObj(REDISKEY);
        System.out.print("size="+dataList.size());



       /*redisTemplate.opsForHash().put(REDISKEY,"111",JSON.toJSONString(testService.getDspDetailList()));
        System.out.print("redis..");

        JSON.parseObject(redisTemplate.opsForHash().get(REDISKEY,"111"),DspDetailVO.class);
        JSON.toJavaObject(redisTemplate.opsForHash().get(REDISKEY,"111"),List<DspDetailVO>);
        List<DspDetailVO> dataList= (List<DspDetailVO>) redisTemplate.opsForHash().get(REDISKEY,"111");

        System.out.print(redisTemplate.opsForHash().get(REDISKEY,"111"));
        System.out.print("size="+dataList.size());
        */
        return testService.getDspDetailList();
    }




}
